home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / emacs-6.z / emacs-6
Encoding:
GNU Info File  |  1994-08-02  |  45.4 KB  |  1,045 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
  6.  
  7. Transposing Text
  8. ================
  9.  
  10. `C-t'
  11.      Transpose two characters (`transpose-chars').
  12.  
  13. `M-t'
  14.      Transpose two words (`transpose-words').
  15.  
  16. `C-M-t'
  17.      Transpose two balanced expressions (`transpose-sexps').
  18.  
  19. `C-x C-t'
  20.      Transpose two lines (`transpose-lines').
  21.  
  22.    The common error of transposing two characters can be fixed, when
  23. they are adjacent, with the `C-t' command (`transpose-chars').
  24. Normally, `C-t' transposes the two characters on either side of point.
  25. When given at the end of a line, rather than transposing the last
  26. character of the line with the newline, which would be useless, `C-t'
  27. transposes the last two characters on the line.  So, if you catch your
  28. transposition error right away, you can fix it with just a `C-t'.  If
  29. you don't catch it so fast, you must move the cursor back to between
  30. the two transposed characters.  If you transposed a space with the last
  31. character of the word before it, the word motion commands are a good
  32. way of getting there.  Otherwise, a reverse search (`C-r') is often the
  33. best way.  *Note Search::.
  34.  
  35.    `M-t' (`transpose-words') transposes the word before point with the
  36. word after point.  It moves point forward over a word, dragging the
  37. word preceding or containing point forward as well.  The punctuation
  38. characters between the words do not move.  For example, `FOO, BAR'
  39. transposes into `BAR, FOO' rather than `BAR FOO,'.
  40.  
  41.    `C-M-t' (`transpose-sexps') is a similar command for transposing two
  42. expressions (*note Lists::.), and `C-x C-t' (`transpose-lines')
  43. exchanges lines.  They work like `M-t' except in determining the
  44. division of the text into syntactic units.
  45.  
  46.    A numeric argument to a transpose command serves as a repeat count:
  47. it tells the transpose command to move the character (word, sexp, line)
  48. before or containing point across several other characters (words,
  49. sexps, lines).  For example, `C-u 3 C-t' moves the character before
  50. point forward across three other characters.  It would change
  51. `f-!-oobar' into `oobf-!-ar'.  This is equivalent to repeating `C-t'
  52. three times.  `C-u - 4 M-t' moves the word before point backward across
  53. four words.  `C-u - C-M-t' would cancel the effect of plain `C-M-t'.
  54.  
  55.    A numeric argument of zero is assigned a special meaning (because
  56. otherwise a command with a repeat count of zero would do nothing): to
  57. transpose the character (word, sexp, line) ending after point with the
  58. one ending after the mark.
  59.  
  60. 
  61. File: emacs,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
  62.  
  63. Case Conversion
  64. ===============
  65.  
  66. `M-- M-l'
  67.      Convert last word to lower case.  Note `Meta--' is Meta-minus.
  68.  
  69. `M-- M-u'
  70.      Convert last word to all upper case.
  71.  
  72. `M-- M-c'
  73.      Convert last word to lower case with capital initial.
  74.  
  75.    A very common error is to type words in the wrong case.  Because of
  76. this, the word case-conversion commands `M-l', `M-u' and `M-c' have a
  77. special feature when used with a negative argument: they do not move the
  78. cursor.  As soon as you see you have mistyped the last word, you can
  79. simply case-convert it and go on typing.  *Note Case::.
  80.  
  81. 
  82. File: emacs,  Node: Spelling,  Prev: Fixing Case,  Up: Fixit
  83.  
  84. Checking and Correcting Spelling
  85. ================================
  86.  
  87.    This section describes the commands to check the spelling of a single
  88. word or of a portion of a buffer.
  89.  
  90. `M-$'
  91.      Check and correct spelling of word at point (`ispell-word').
  92.  
  93. `M-x ispell-buffer'
  94.      Check and correct spelling of each word in the buffer.
  95.  
  96. `M-x ispell-region'
  97.      Check and correct spelling of each word in the region.
  98.  
  99. `M-x ispell-string RET WORD RET'
  100.      Check spelling of WORD.
  101.  
  102. `M-x ispell-complete-word'
  103.      Complete the word before point based on the spelling dictionary.
  104.  
  105. `M-x reload-ispell'
  106.      Make the Ispell subprocess reread your private dictionary.
  107.  
  108. `M-x kill-ispell'
  109.      Kill the Ispell subprocess.
  110.  
  111.    To check the spelling of the word around or next to point, and
  112. optionally correct it as well, use the command `M-$' (`ispell-word').
  113. If the word is not correct, the command offers you various alternatives
  114. for what to do about it.
  115.  
  116.    To check the entire current buffer, use `M-x ispell-buffer'.  Use
  117. `M-x ispell-region' to check just the current region.  Each time these
  118. commands encounter an incorrect word, they ask you what to do.
  119.  
  120.    Whenever one of these commands finds an incorrect word, it displays a
  121. list of alternatives, usually including several "near-misses"--words
  122. that are close to the word being checked.  Here are the valid responses:
  123.  
  124. `SPC'
  125.      Skip this word--continue to consider it incorrect, but don't
  126.      change it here.
  127.  
  128. `r NEW RET'
  129.      Replace the word (just this time) with NEW.
  130.  
  131. `DIGIT'
  132.      Replace the word (just this time) with one of the displayed
  133.      near-misses.  Each near-miss is listed with a digit; type that
  134.      digit to select it.
  135.  
  136. `a'
  137.      Accept the incorrect word--treat it as correct, but only in this
  138.      editing session.
  139.  
  140. `i'
  141.      Insert this word in your private dictionary file so that Ispell
  142.      will consider it correct it from now on, even in future sessions.
  143.  
  144. `l REGEXP RET'
  145.      Look in the dictionary for words that match REGEXP.  These words
  146.      become the new list of "near-misses"; you can select one of them to
  147.      replace with by typing a digit.
  148.  
  149. `C-g'
  150.      Quit interactive spell checking.  You can restart it again
  151.      afterward with `C-u M-$'.
  152.  
  153.    The command `ispell-complete-word', which is bound to the key
  154. `M-TAB' in Text mode and related modes, performs completion based on
  155. spelling correction.  Insert the beginning of a word, and then type
  156. `M-TAB'; the command inserts as many more letters as can be uniquely
  157. determined from the letters in the buffer, based on your currently
  158. loaded dictionaries.  *Note Text Mode::.
  159.  
  160.    The first time you use any of the spell checking commands, it starts
  161. an Ispell subprocess.  The first thing the subprocess does is read your
  162. private dictionary, which is the file `~/ispell.words'.  Words that you
  163. "insert" with the `i' command are added to that file, but not right
  164. away--only at the end of the interactive replacement procedure.  Use
  165. the `M-x reload-ispell' command to reload your private dictionary from
  166. `~/ispell.words' if you edit the file outside of Ispell.
  167.  
  168.    Once started, the Ispell subprocess continues to run (waiting for
  169. something to do), so that subsequent spell checking commands complete
  170. more quickly.  If you want to get rid of the Ispell process, use `M-x
  171. kill-ispell'.  This is not usually necessary, since the process uses no
  172. time except when you do spelling correction.
  173.  
  174. 
  175. File: emacs,  Node: Files,  Next: Buffers,  Prev: Fixit,  Up: Top
  176.  
  177. File Handling
  178. *************
  179.  
  180.    The basic unit of stored data in Unix is the "file".  To edit a file,
  181. you must tell Emacs to examine the file and prepare a buffer containing
  182. a copy of the file's text.  This is called "visiting" the file.  Editing
  183. commands apply directly to text in the buffer; that is, to the copy
  184. inside Emacs.  Your changes appear in the file itself only when you
  185. "save" the buffer back into the file.
  186.  
  187.    In addition to visiting and saving files, Emacs can delete, copy,
  188. rename, and append to files, keep multiple versions of them, and operate
  189. on file directories.
  190.  
  191. * Menu:
  192.  
  193. * File Names::       How to type and edit file name arguments.
  194. * Visiting::         Visiting a file prepares Emacs to edit the file.
  195. * Saving::           Saving makes your changes permanent.
  196. * Reverting::        Reverting cancels all the changes not saved.
  197. * Auto Save::        Auto Save periodically protects against loss of data.
  198. * File Aliases::     Handling multiple names for one file.
  199. * Version Control::  Version control systems (RCS and SCCS).
  200. * ListDir::          Listing the contents of a file directory.
  201. * Comparing Files::  Finding where two files differ.
  202. * Misc File Ops::    Other things you can do on files.
  203.  
  204. 
  205. File: emacs,  Node: File Names,  Next: Visiting,  Up: Files
  206.  
  207. File Names
  208. ==========
  209.  
  210.    Most Emacs commands that operate on a file require you to specify the
  211. file name.  (Saving and reverting are exceptions; the buffer knows which
  212. file name to use for them.)  You enter the file name using the
  213. minibuffer (*note Minibuffer::.).  "Completion" is available, to make
  214. it easier to specify long file names.  *Note Completion::.
  215.  
  216.    For most operations, there is a "default file name" which is used if
  217. you type just RET to enter an empty argument.  Normally the default
  218. file name is the name of the file visited in the current buffer; this
  219. makes it easy to operate on that file with any of the Emacs file
  220. commands.
  221.  
  222.    Each buffer has a default directory, normally the same as the
  223. directory of the file visited in that buffer.  When you enter a file
  224. name without a directory, the default directory is used.  If you specify
  225. a directory in a relative fashion, with a name that does not start with
  226. a slash, it is interpreted with respect to the default directory.  The
  227. default directory is kept in the variable `default-directory', which
  228. has a separate value in every buffer.
  229.  
  230.    For example, if the default file name is `/u/rms/gnu/gnu.tasks' then
  231. the default directory is `/u/rms/gnu/'.  If you type just `foo', which
  232. does not specify a directory, it is short for `/u/rms/gnu/foo'.
  233. `../.login' would stand for `/u/rms/.login'.  `new/foo' would stand for
  234. the file name `/u/rms/gnu/new/foo'.
  235.  
  236.    The command `M-x pwd' prints the current buffer's default directory,
  237. and the command `M-x cd' sets it (to a value read using the
  238. minibuffer).  A buffer's default directory changes only when the `cd'
  239. command is used.  A file-visiting buffer's default directory is
  240. initialized to the directory of the file that is visited there.  If you
  241. create a buffer with `C-x b', its default directory is copied from that
  242. of the buffer that was current at the time.
  243.  
  244.    The default directory actually appears in the minibuffer when the
  245. minibuffer becomes active to read a file name.  This serves two
  246. purposes: it *shows* you what the default is, so that you can type a
  247. relative file name and know with certainty what it will mean, and it
  248. allows you to *edit* the default to specify a different directory.
  249. This insertion of the default directory is inhibited if the variable
  250. `insert-default-directory' is set to `nil'.
  251.  
  252.    Note that it is legitimate to type an absolute file name after you
  253. enter the minibuffer, ignoring the presence of the default directory
  254. name as part of the text.  The final minibuffer contents may look
  255. invalid, but that is not so.  For example, if the minibuffer starts out
  256. with `/usr/tmp/' and you add `/x1/rms/foo', the double slash says to
  257. ignore the default directory and use just the name that you typed.
  258. *Note Minibuffer File::.
  259.  
  260.    You can refer to files on other machines using a special file name
  261. syntax:
  262.  
  263.      /HOST:FILENAME
  264.      /USER@HOST:FILENAME
  265.  
  266.    When you do this, Emacs uses the FTP program to read and write files
  267. on the specified host.  It logs in through FTP using your user name or
  268. the name USER.  It may ask you for a password from time to time; this
  269. is used for logging in on HOST.
  270.  
  271.    `$' in a file name is used to substitute environment variables.  For
  272. example, if you have used the shell command `setenv FOO rms/hacks' to
  273. set up an environment variable named `FOO', then you can use
  274. `/u/$FOO/test.c' or `/u/${FOO}/test.c' as an abbreviation for
  275. `/u/rms/hacks/test.c'.  The environment variable name consists of all
  276. the alphanumeric characters after the `$'; alternatively, it may be
  277. enclosed in braces after the `$'.  Note that the `setenv' command
  278. affects Emacs only if done before Emacs is started.
  279.  
  280.    To access a file with `$' in its name, type `$$'.  This pair is
  281. converted to a single `$' at the same time as variable substitution is
  282. performed for single `$'.  The Lisp function that performs the
  283. substitution is called `substitute-in-file-name'.  The substitution is
  284. performed only on file names read as such using the minibuffer.
  285.  
  286. 
  287. File: emacs,  Node: Visiting,  Next: Saving,  Prev: File Names,  Up: Files
  288.  
  289. Visiting Files
  290. ==============
  291.  
  292. `C-x C-f'
  293.      Visit a file (`find-file').
  294.  
  295. `C-x C-r'
  296.      Visit a file for viewing, without allowing changes to it
  297.      (`find-file-read-only').
  298.  
  299. `C-x C-v'
  300.      Visit a different file instead of the one visited last
  301.      (`find-alternate-file').
  302.  
  303. `C-x 4 C-f'
  304.      Visit a file, in another window (`find-file-other-window').  Don't
  305.      change the selected window.
  306.  
  307. `C-x 5 C-f'
  308.      Visit a file, in a new frame (`find-file-other-frame').  Don't
  309.      change the selected frame.
  310.  
  311.    "Visiting" a file means copying its contents into an Emacs buffer so
  312. you can edit them.  Emacs makes a new buffer for each file that you
  313. visit.  We say that this buffer is visiting the file that it was created
  314. to hold.  Emacs constructs the buffer name from the file name by
  315. throwing away the directory, keeping just the name proper.  For example,
  316. a file named `/usr/rms/emacs.tex' would get a buffer named `emacs.tex'.
  317. If there is already a buffer with that name, a unique name is
  318. constructed by appending `<2>', `<3>', or so on, using the lowest
  319. number that makes a name that is not already in use.
  320.  
  321.    Each window's mode line shows the name of the buffer that is being
  322. displayed in that window, so you can always tell what buffer you are
  323. editing.
  324.  
  325.    The changes you make with Emacs are made in the Emacs buffer.  They
  326. do not take effect in the file that you visited, or any place
  327. permanent, until you "save" the buffer.  Saving the buffer means that
  328. Emacs writes the current contents of the buffer into its visited file.
  329. *Note Saving::.
  330.  
  331.    If a buffer contains changes that have not been saved, we say the
  332. buffer is "modified".  This is important because it implies that some
  333. changes will be lost if the buffer is not saved.  The mode line
  334. displays two stars near the left margin to indicate that the buffer is
  335. modified.
  336.  
  337.    To visit a file, use the command `C-x C-f' (`find-file').  Follow
  338. the command with the name of the file you wish to visit, terminated by a
  339. RET.
  340.  
  341.    The file name is read using the minibuffer (*note Minibuffer::.),
  342. with defaulting and completion in the standard manner (*note File
  343. Names::.).  While in the minibuffer, you can abort `C-x C-f' by typing
  344. `C-g'.
  345.  
  346.    Your confirmation that `C-x C-f' has completed successfully is the
  347. appearance of new text on the screen and a new buffer name in the mode
  348. line.  If the specified file does not exist and could not be created, or
  349. cannot be read, then you get an error, with an error message displayed
  350. in the echo area.
  351.  
  352.    If you visit a file that is already in Emacs, `C-x C-f' does not make
  353. another copy.  It selects the existing buffer containing that file.
  354. However, before doing so, it checks that the file itself has not changed
  355. since you visited or saved it last.  If the file has changed, a warning
  356. message is printed.  *Note Simultaneous Editing: Interlocking.
  357.  
  358.    What if you want to create a new file?  Just visit it.  Emacs prints
  359. `(New File)' in the echo area, but in other respects behaves as if you
  360. had visited an existing empty file.  If you make any changes and save
  361. them, the file is created.
  362.  
  363.    If the file you specify is actually a directory, Dired is called on
  364. that directory (*note Dired::.).  This can be inhibited by setting the
  365. variable `find-file-run-dired' to `nil'; then it is an error to try to
  366. visit a directory.
  367.  
  368.    If you visit a file that the operating system won't let you modify,
  369. Emacs makes the buffer read-only, so that you won't go ahead and make
  370. changes that you'll have trouble saving afterward.  You can make the
  371. buffer writable with `C-x C-q' (`toggle-read-only').  *Note Misc
  372. Buffer::.
  373.  
  374.    Occasionally you might want to visit a file as read-only in order to
  375. protect yourself from entering changes accidentally; do so by visiting
  376. the file with the command `C-x C-r' (`find-file-read-only').
  377.  
  378.    If you visit a nonexistent file unintentionally (because you typed
  379. the wrong file name), use the `C-x C-v' command (`find-alternate-file')
  380. to visit the file you really wanted.  `C-x C-v' is similar to `C-x
  381. C-f', but it kills the current buffer (after first offering to save it
  382. if it is modified).  When it reads the file name to visit, it inserts
  383. the entire default file name in the buffer, with point just after the
  384. directory part; this is convenient if you made a slight error in typing
  385. the name.
  386.  
  387.    `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
  388. the buffer containing the specified file is selected in another window.
  389. The window that was selected before `C-x 4 f' continues to show the
  390. same buffer it was already showing.  If this command is used when only
  391. one window is being displayed, that window is split in two, with one
  392. window showing the same buffer as before, and the other one showing the
  393. newly requested file.  *Note Windows::.
  394.  
  395.    `C-x 5 f' (`find-file-other-frame') is similar, but opens a new
  396. frame.  This feature is available only when you are using a window
  397. system.  *Note Frames::.
  398.  
  399.    Two special hook variables allow extensions to modify the operation
  400. of visiting files.  Visiting a file that does not exist runs the
  401. functions in the list `find-file-not-found-hooks'; this variable holds
  402. a list of functions, and the functions are called one by one until one
  403. of them returns non-`nil'.  Any visiting of a file, whether extant or
  404. not, expects `find-file-hooks' to contain a list of functions and calls
  405. them all, one by one.  In both cases the functions receive no
  406. arguments.  Of these two variables, `find-file-not-found-hooks' takes
  407. effect first.  These variables are *not* normal hooks, and their names
  408. end in `-hooks' rather than `-hook' to indicate that fact.
  409.  
  410.    There are several ways to specify automatically the major mode for
  411. editing the file (*note Choosing Modes::.), and to specify local
  412. variables defined for that file (*note File Variables::.).
  413.  
  414. 
  415. File: emacs,  Node: Saving,  Next: Reverting,  Prev: Visiting,  Up: Files
  416.  
  417. Saving Files
  418. ============
  419.  
  420.    "Saving" a buffer in Emacs means writing its contents back into the
  421. file that was visited in the buffer.
  422.  
  423. `C-x C-s'
  424.      Save the current buffer in its visited file (`save-buffer').
  425.  
  426. `C-x s'
  427.      Save any or all buffers in their visited files
  428.      (`save-some-buffers').
  429.  
  430. `M-~'
  431.      Forget that the current buffer has been changed (`not-modified').
  432.  
  433. `C-x C-w'
  434.      Save the current buffer in a specified file (`write-file').
  435.  
  436. `M-x set-visited-file-name'
  437.      Change file the name under which the current buffer will be saved.
  438.  
  439.    When you wish to save the file and make your changes permanent, type
  440. `C-x C-s' (`save-buffer').  After saving is finished, `C-x C-s' prints
  441. a message such as
  442.  
  443.      Wrote /u/rms/gnu/gnu.tasks
  444.  
  445. If the selected buffer is not modified (no changes have been made in it
  446. since the buffer was created or last saved), saving is not really done,
  447. because it would have no effect.  Instead, `C-x C-s' prints a message
  448. in the echo area saying
  449.  
  450.      (No changes need to be written)
  451.  
  452.    The command `C-x s' (`save-some-buffers') offers to save any or all
  453. modified buffers.  It asks you what to do with each buffer.  The
  454. options are analogous to those of `query-replace':
  455.  
  456. `y'
  457.      Save this buffer and ask about the rest of the buffers.
  458.  
  459. `n'
  460.      Don't save this buffer, but ask about the rest of the buffers.
  461.  
  462. `!'
  463.      Save this buffer and all the rest with no more questions.
  464.  
  465. `ESC'
  466.      Terminate `save-some-buffers' without any more saving.
  467.  
  468. `.'
  469.      Save this buffer, then exit `save-some-buffers' without even asking
  470.      about other buffers.
  471.  
  472. `C-r'
  473.      View the buffer that you are currently being asked about.  When
  474.      you exit View mode, you get back to `save-some-buffers', which
  475.      asks the question again.
  476.  
  477. `C-h'
  478.      Display a help message about these options.
  479.  
  480.    `C-x C-c', the key sequence to exit Emacs, invokes
  481. `save-some-buffers' and therefore asks the same questions.
  482.  
  483.    If you have changed a buffer and do not want the changes to be saved,
  484. you should take some action to prevent it.  Otherwise, each time you use
  485. `C-x s' or `C-x C-c', you are liable to save it by mistake.  One thing
  486. you can do is type `M-~' (`not-modified'), which clears out the
  487. indication that the buffer is modified.  If you do this, none of the
  488. save commands will believe that the buffer needs to be saved.  (`~' is
  489. often used as a mathematical symbol for `not'; thus `M-~' is `not',
  490. metafied.)  You could also use `set-visited-file-name' (see below) to
  491. mark the buffer as visiting a different file name, one which is not in
  492. use for anything important.  Alternatively, you can cancel all the
  493. changes made since the file was visited or saved, by reading the text
  494. from the file again.  This is called "reverting".  *Note Reverting::.
  495. You could also undo all the changes by repeating the undo command `C-x
  496. u' until you have undone all the changes; but reverting is easier.
  497.  
  498.    `M-x set-visited-file-name' alters the name of the file that the
  499. current buffer is visiting.  It reads the new file name using the
  500. minibuffer.  Then it specifies the visited file name and changes the
  501. buffer name correspondingly (as long as the new name is not in use).
  502. `set-visited-file-name' does not save the buffer in the newly visited
  503. file; it just alters the records inside Emacs in case you do save
  504. later.  It also marks the buffer as "modified" so that `C-x C-s' in
  505. that buffer *will* save.
  506.  
  507.    If you wish to mark the buffer as visiting a different file and save
  508. it right away, use `C-x C-w' (`write-file').  It is precisely
  509. equivalent to `set-visited-file-name' followed by `C-x C-s'.  `C-x C-s'
  510. used on a buffer that is not visiting with a file has the same effect
  511. as `C-x C-w'; that is, it reads a file name, marks the buffer as
  512. visiting that file, and saves it there.  The default file name in a
  513. buffer that is not visiting a file is made by combining the buffer name
  514. with the buffer's default directory.
  515.  
  516.    If Emacs is about to save a file and sees that the date of the latest
  517. version on disk does not match what Emacs last read or wrote, Emacs
  518. notifies you of this fact, because it probably indicates a problem
  519. caused by simultaneous editing and requires your immediate attention.
  520. *Note Simultaneous Editing: Interlocking.
  521.  
  522.    If the variable `require-final-newline' is non-`nil', Emacs puts a
  523. newline at the end of any file that doesn't already end in one, every
  524. time a file is saved or written.
  525.  
  526.    You can implement other ways to write files, and other things to be
  527. done before writing them, using the variable `write-file-hooks'.  The
  528. value of this variable should be a list of Lisp functions.  When a file
  529. is to be written, the functions in the list are called, one by one,
  530. with no arguments.  If one of them returns a non-`nil' value, Emacs
  531. takes this to mean that the file has been written in some suitable
  532. fashion; the rest of the functions are not called, and normal writing
  533. is not done.  If this variable is local to a buffer, changing major
  534. modes does not clear it.  However, changing the visited file name does
  535. clear this variable to `nil'.
  536.  
  537.    The list `local-write-file-hooks' is used just like
  538. `write-file-hooks'.  This list is for use as a local variable.  It is a
  539. permanent local, so that switching major modes does not affect it.
  540.  
  541.    The variable `write-contents-hooks' holds another list of functions
  542. to be called before writing out a buffer to a file.  These functions
  543. are used just like the ones in `write-file-hooks'.  The difference
  544. between this and `write-file-hooks' is that changing the major mode
  545. does clear this variable, and setting the visited file name does not
  546. clear it.
  547.  
  548.    The hook functions are responsible for writing backup files, if you
  549. want that to be done.  Here is how:
  550.  
  551.      (or buffer-backed-up (backup-buffer))
  552.  
  553. You might also wish to save the file modes value returned by
  554. `backup-buffer' and use that to set the mode bits of the file that you
  555. write.  This is what happens ordinarily when backups are made.
  556.  
  557.    The hook variables described here are not normal hooks, because the
  558. values returned by the hook functions do matter.  This is why they have
  559. names ending in `-hooks' rather than `-hook'.  *Note Hooks::.
  560.  
  561. * Menu:
  562.  
  563. * Backup::        How Emacs saves the old version of your file.
  564. * Interlocking::  How Emacs protects against simultaneous editing
  565.                     of one file by two users.
  566.  
  567. 
  568. File: emacs,  Node: Backup,  Next: Interlocking,  Up: Saving
  569.  
  570. Backup Files
  571. ------------
  572.  
  573.    Because Unix does not provide version numbers in file names,
  574. rewriting a file in Unix automatically destroys all record of what the
  575. file used to contain.  Thus, saving a file from Emacs throws away the
  576. old contents of the file--or it would, except that Emacs carefully
  577. copies the old contents to another file, called the "backup" file,
  578. before actually saving.  (This assumes that the variable
  579. `make-backup-files' is non-`nil'.  Backup files are not written if this
  580. variable is `nil'.)
  581.  
  582.    At your option, Emacs can keep either a single backup file or a
  583. series of numbered backup files for each file that you edit.
  584.  
  585.    Emacs makes a backup for a file only the first time the file is saved
  586. from one buffer.  No matter how many times you save a file, its backup
  587. file continues to contain the contents from before the file was visited.
  588. Normally this means that the backup file contains the contents from
  589. before the current editing session; however, if you kill the buffer and
  590. then visit the file again, a new backup file will be made by the next
  591. save.
  592.  
  593. * Menu:
  594.  
  595. * Names: Backup Names.        How backup files are named;
  596.                   choosing single or numbered backup files.
  597. * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
  598. * Copying: Backup Copying.    Backups can be made by copying or renaming.
  599.  
  600. 
  601. File: emacs,  Node: Backup Names,  Next: Backup Deletion,  Up: Backup
  602.  
  603. Single or Numbered Backups
  604. ..........................
  605.  
  606.    If you choose to have a single backup file (this is the default),
  607. the backup file's name is constructed by appending `~' to the file name
  608. being edited; thus, the backup file for `eval.c' would be `eval.c~'.
  609.  
  610.    If you choose to have a series of numbered backup files, backup file
  611. names are made by appending `.~', the number, and another `~' to the
  612. original file name.  Thus, the backup files of `eval.c' would be called
  613. `eval.c.~1~', `eval.c.~2~', and so on, through names like
  614. `eval.c.~259~' and beyond.
  615.  
  616.    If protection stops you from writing backup files under the usual
  617. names, the backup file is written as `%backup%~' in your home directory.
  618. Only one such file can exist, so only the most recently made such
  619. backup is available.
  620.  
  621.    The choice of single backup or numbered backups is controlled by the
  622. variable `version-control'.  Its possible values are
  623.  
  624. `t'
  625.      Make numbered backups.
  626.  
  627. `nil'
  628.      Make numbered backups for files that have numbered backups already.
  629.      Otherwise, make single backups.
  630.  
  631. `never'
  632.      Do not in any case make numbered backups; always make single
  633.      backups.
  634.  
  635. You can set `version-control' locally in an individual buffer to
  636. control the making of backups for that buffer's file.  For example,
  637. Rmail mode locally sets `version-control' to `never' to make sure that
  638. there is only one backup for an Rmail file.  *Note Locals::.
  639.  
  640.    If you set the environment variable `VERSION_CONTROL', to tell
  641. various GNU utilities what to do with backup files, Emacs also obeys the
  642. environment variable by setting the Lisp variable `version-control'
  643. accordingly at startup.  If the environment variable's value is `t' or
  644. `numbered', then `version-control' becomes `t'; if the value is `nil'
  645. or `existing', then `version-control' becomes `nil'; if it is `never'
  646. or `simple', then `version-control' becomes `never'.
  647.  
  648. 
  649. File: emacs,  Node: Backup Deletion,  Next: Backup Copying,  Prev: Backup Names,  Up: Backup
  650.  
  651. Automatic Deletion of Backups
  652. .............................
  653.  
  654.    To prevent unlimited consumption of disk space, Emacs can delete
  655. numbered backup versions automatically.  Generally Emacs keeps the
  656. first few backups and the latest few backups, deleting any in between.
  657. This happens every time a new backup is made.
  658.  
  659.    The two variables `kept-old-versions' and `kept-new-versions'
  660. control this deletion.  Their values are, respectively the number of
  661. oldest (lowest-numbered) backups to keep and the number of newest
  662. (highest-numbered) ones to keep, each time a new backup is made.
  663. Recall that these values are used just after a new backup version is
  664. made; that newly made backup is included in the count in
  665. `kept-new-versions'.  By default, both variables are 2.
  666.  
  667.    If `trim-versions-without-asking' is non-`nil', the excess middle
  668. versions are deleted without a murmur.  If it is `nil', the default,
  669. then you are asked whether the excess middle versions should really be
  670. deleted.
  671.  
  672.    Dired's `.' (Period) command can also be used to delete old versions.
  673. *Note Dired Deletion::.
  674.  
  675. 
  676. File: emacs,  Node: Backup Copying,  Prev: Backup Deletion,  Up: Backup
  677.  
  678. Copying vs. Renaming
  679. ....................
  680.  
  681.    Backup files can be made by copying the old file or by renaming it.
  682. This makes a difference when the old file has multiple names.  If the
  683. old file is renamed into the backup file, then the alternate names
  684. become names for the backup file.  If the old file is copied instead,
  685. then the alternate names remain names for the file that you are
  686. editing, and the contents accessed by those names will be the new
  687. contents.
  688.  
  689.    The method of making a backup file may also affect the file's owner
  690. and group.  If copying is used, these do not change.  If renaming is
  691. used, you become the file's owner, and the file's group becomes the
  692. default (different operating systems have different defaults for the
  693. group).
  694.  
  695.    Having the owner change is usually a good idea, because then the
  696. owner always shows who last edited the file.  Also, the owners of the
  697. backups show who produced those versions.  Occasionally there is a file
  698. whose owner should not change; it is a good idea for such files to
  699. contain local variable lists to set `backup-by-copying-when-mismatch'
  700. locally (*note File Variables::.).
  701.  
  702.    The choice of renaming or copying is controlled by three variables.
  703. Renaming is the default choice.  If the variable `backup-by-copying' is
  704. non-`nil', copying is used.  Otherwise, if the variable
  705. `backup-by-copying-when-linked' is non-`nil', then copying is used for
  706. files that have multiple names, but renaming may still used when the
  707. file being edited has only one name.  If the variable
  708. `backup-by-copying-when-mismatch' is non-`nil', then copying is used if
  709. renaming would cause the file's owner or group to change.
  710.  
  711. 
  712. File: emacs,  Node: Interlocking,  Prev: Backup,  Up: Saving
  713.  
  714. Protection against Simultaneous Editing
  715. ---------------------------------------
  716.  
  717.    Simultaneous editing occurs when two users visit the same file, both
  718. make changes, and then both save them.  If nobody were informed that
  719. this was happening, whichever user saved first would later find that his
  720. changes were lost.  On some systems, Emacs notices immediately when the
  721. second user starts to change the file, and issues an immediate warning.
  722.  
  723.    For the sake of systems where that is not possible, and in case
  724. someone else proceeds to change the file despite the warning, Emacs also
  725. checks when the file is saved, and issues a second warning if you are
  726. about to overwrite a file containing another user's changes.  You can
  727. prevent loss of the other user's work by taking the proper corrective
  728. action at that time.
  729.  
  730.    When you make the first modification in an Emacs buffer that is
  731. visiting a file, Emacs records that  the file is "locked" by you.  (It
  732. does this by writing another file in a directory reserved for this
  733. purpose.)  The lock is removed when you save the changes.  The idea is
  734. that the file is locked whenever an Emacs buffer visiting it has
  735. unsaved changes.
  736.  
  737.    If you begin to modify the buffer while the visited file is locked by
  738. someone else, this constitutes a "collision".  When Emacs detects a
  739. collision, it asks you what to do, by calling the Lisp function
  740. `ask-user-about-lock'.  You can redefine this function for the sake of
  741. customization.  The standard definition of this function asks you a
  742. question and accepts three possible answers:
  743.  
  744. `s'
  745.      Steal the lock.  Whoever was already changing the file loses the
  746.      lock, and you gain the lock.
  747.  
  748. `p'
  749.      Proceed.  Go ahead and edit the file despite its being locked by
  750.      someone else.
  751.  
  752. `q'
  753.      Quit.  This causes an error (`file-locked') and the modification
  754.      you were trying to make in the buffer does not actually take place.
  755.  
  756.    Note that locking works on the basis of a file name; if a file has
  757. multiple names, Emacs does not realize that the two names are the same
  758. file and cannot prevent two users from editing it simultaneously under
  759. different names.  However, basing locking on names means that Emacs can
  760. interlock the editing of new files that will not really exist until
  761. they are saved.
  762.  
  763.    Some systems are not configured to allow Emacs to make locks.  On
  764. these systems, Emacs cannot detect trouble in advance, but it still can
  765. detect the collision when you try to save a file and overwrite someone
  766. else's changes.
  767.  
  768.    Every time Emacs saves a buffer, it first checks the
  769. last-modification date of the existing file on disk to verify that it
  770. has not changed since the file was last visited or saved.  If the date
  771. does not match, it implies that changes were made in the file in some
  772. other way, and these changes are about to be lost if Emacs actually
  773. does save.  To prevent this, Emacs prints a warning message and asks
  774. for confirmation before saving.  Occasionally you will know why the
  775. file was changed and know that it does not matter; then you can answer
  776. `yes' and proceed.  Otherwise, you should cancel the save with `C-g'
  777. and investigate the situation.
  778.  
  779.    The first thing you should do when notified that simultaneous
  780. editing has already taken place is to list the directory with `C-u C-x
  781. C-d' (*note Directory Listing: ListDir.).  This  shows the file's
  782. current author.  You should attempt to contact him to warn him not to
  783. continue editing.  Often the next step is to save the contents of your
  784. Emacs buffer under a different name, and use `diff' to compare the two
  785. files.
  786.  
  787.    Simultaneous editing checks are also made when you visit with `C-x
  788. C-f' a file that is already visited and when you start to modify a
  789. file.  This is not strictly necessary, but it can cause you to find out
  790. about the collision earlier, when perhaps correction takes less work.
  791.  
  792. 
  793. File: emacs,  Node: Reverting,  Next: Auto Save,  Prev: Saving,  Up: Files
  794.  
  795. Reverting a Buffer
  796. ==================
  797.  
  798.    If you have made extensive changes to a file and then change your
  799. mind about them, you can get rid of them by reading in the previous
  800. version of the file.  To do this, use `M-x revert-buffer', which
  801. operates on the current buffer.  Since this is a very dangerous thing
  802. to do, you must confirm it with `yes'.
  803.  
  804.    `revert-buffer' keeps point at the same distance (measured in
  805. characters) from the beginning of the file.  If the file was edited only
  806. slightly, you will be at approximately the same piece of text after
  807. reverting as before.  If you have made drastic changes, the same value
  808. of point in the old file may address a totally different piece of text.
  809.  
  810.    Reverting marks the buffer as "not modified" until another change is
  811. made.
  812.  
  813.    Some kinds of buffers whose contents reflect data bases other than
  814. files, such as Dired buffers, can also be reverted.  For them,
  815. reverting means recalculating their contents from the appropriate data
  816. base.  Buffers created randomly with `C-x b' cannot be reverted;
  817. `revert-buffer' reports an error when asked to do so.
  818.  
  819. 
  820. File: emacs,  Node: Auto Save,  Next: File Aliases,  Prev: Reverting,  Up: Files
  821.  
  822. Auto-Saving: Protection Against Disasters
  823. =========================================
  824.  
  825.    Emacs saves all the visited files from time to time (based on
  826. counting your keystrokes) without being asked.  This is called
  827. "auto-saving".  It prevents you from losing more than a limited amount
  828. of work if the system crashes.
  829.  
  830.    When Emacs determines that it is time for auto-saving, each buffer is
  831. considered, and is auto-saved if auto-saving is turned on for it and it
  832. has been changed since the last time it was auto-saved.  If any
  833. auto-saving is done, the message `Auto-saving...' is displayed in the
  834. echo area until auto-saving is finished.  Errors occurring during
  835. auto-saving are caught so that they do not interfere with the execution
  836. of commands you have been typing.
  837.  
  838. * Menu:
  839.  
  840. * Files: Auto Save Files.       The file where auto-saved changes are
  841.                                   actually made until you save the file.
  842. * Control: Auto Save Control.   Controlling when and how often to auto-save.
  843. * Recover::                Recovering text from auto-save files.
  844.  
  845. 
  846. File: emacs,  Node: Auto Save Files,  Next: Auto Save Control,  Up: Auto Save
  847.  
  848. Auto-Save Files
  849. ---------------
  850.  
  851.    Auto-saving does not normally save in the files that you visited,
  852. because it can be very undesirable to save a program that is in an
  853. inconsistent state when you have made half of a planned change.
  854. Instead, auto-saving is done in a different file called the "auto-save
  855. file", and the visited file is changed only when you request saving
  856. explicitly (such as with `C-x C-s').
  857.  
  858.    Normally, the auto-save file name is made by appending `#' to the
  859. front and rear of the visited file name.  Thus, a buffer visiting file
  860. `foo.c' is auto-saved in a file `#foo.c#'.  Most buffers that are not
  861. visiting files are auto-saved only if you request it explicitly; when
  862. they are auto-saved, the auto-save file name is made by appending `#%'
  863. to the front and `#' to the rear of buffer name.  For example, the
  864. `*mail*' buffer in which you compose messages to be sent is auto-saved
  865. in a file named `#%*mail*#'.  Auto-save file names are made this way
  866. unless you reprogram parts of Emacs to do something different (the
  867. functions `make-auto-save-file-name' and `auto-save-file-name-p').  The
  868. file name to be used for auto-saving in a buffer is calculated when
  869. auto-saving is turned on in that buffer.
  870.  
  871.    If you want auto-saving to be done in the visited file, set the
  872. variable `auto-save-visited-file-name' to be non-`nil'.  In this mode,
  873. there is really no difference between auto-saving and explicit saving.
  874.  
  875.    A buffer's auto-save file is deleted when you save the buffer in its
  876. visited file.  To inhibit this, set the variable
  877. `delete-auto-save-files' to `nil'.  Changing the visited file name with
  878. `C-x C-w' or `set-visited-file-name' renames any auto-save file to go
  879. with the new visited name.
  880.  
  881.    When you delete a large amount of a buffer's text, auto-saving turns
  882. off in that buffer.  This is because if you deleted the text
  883. unintentionally, you might find the auto-save file more useful if it
  884. contains the deleted text.  To restart auto-saving in that buffer, use
  885. `M-x auto-save' with a positive argument.
  886.  
  887. 
  888. File: emacs,  Node: Auto Save Control,  Next: Recover,  Prev: Auto Save Files,  Up: Auto Save
  889.  
  890. Controlling Auto-Saving
  891. -----------------------
  892.  
  893.    Each time you visit a file, auto-saving is turned on for that file's
  894. buffer if the variable `auto-save-default' is non-`nil' (but not in
  895. batch mode; *note Entering Emacs::.).  The default for this variable is
  896. `t', so auto-saving is the usual practice for file-visiting buffers.
  897. Auto-saving can be turned on or off for any existing buffer with the
  898. command `M-x auto-save-mode'.  Like other minor mode commands, `M-x
  899. auto-save-mode' turns auto-saving on with a positive argument, off with
  900. a zero or negative argument; with no argument, it toggles.
  901.  
  902.    Emacs does auto-saving periodically based on counting how many
  903. characters you have typed since the last time auto-saving was done.
  904. The variable `auto-save-interval' specifies how many characters there
  905. are between auto-saves.  By default, it is 300.
  906.  
  907.    Auto-saving also takes place when you stop typing for a while.  The
  908. variable `auto-save-timeout' says how many seconds Emacs should wait
  909. before it does an auto save (and perhaps also a garbage collection).
  910. (The actual time period is longer if the current buffer is long; this
  911. is a heuristic which aims to keep out of your way when you are editing
  912. long buffers in which auto-save takes an appreciable amount of time.)
  913. Auto-saving during idle periods accomplishes two things: first, it
  914. makes sure all your work is saved if you go away from the terminal for
  915. a while; second, it may avoid some auto-saving while you are actually
  916. typing.
  917.  
  918.    Emacs also does auto-saving whenever it gets a fatal error.  This
  919. includes killing the Emacs job with a shell command such as `kill
  920. %emacs', or disconnecting a phone line or network connection.
  921.  
  922.    You can request an auto-save explicitly with the command `M-x
  923. do-auto-save'.
  924.  
  925. 
  926. File: emacs,  Node: Recover,  Prev: Auto Save Control,  Up: Auto Save
  927.  
  928. Recovering Data from Auto-Saves
  929. -------------------------------
  930.  
  931.    The way to use the contents of an auto-save file to recover from a
  932. loss of data is with the command `M-x recover-file RET FILE RET'.  This
  933. visits FILE and then (after your confirmation) restores the contents
  934. from from its auto-save file `#FILE#'.  You can then save with `C-x
  935. C-s' to put the recovered text into FILE itself.  For example, to
  936. recover file `foo.c' from its auto-save file `#foo.c#', do:
  937.  
  938.      M-x recover-file RET foo.c RET
  939.      yes RET
  940.      C-x C-s
  941.  
  942.    Before asking for confirmation, `M-x recover-file' displays a
  943. directory listing describing the specified file and the auto-save file,
  944. so you can compare their sizes and dates.  If the auto-save file is
  945. older, `M-x recover-file' does not offer to read it.
  946.  
  947. 
  948. File: emacs,  Node: File Aliases,  Next: Version Control,  Prev: Auto Save,  Up: Files
  949.  
  950. File Name Aliases
  951. =================
  952.  
  953.    Symbolic links and hard links both make it possible for several file
  954. names to refer to the same file.  For example, when `foo' is a symbolic
  955. link to `bar', the file has two names, but `bar' is the real name, and
  956. `foo' is just an alias.  More complex cases occur when symbolic links
  957. point to directories.
  958.  
  959.    If you visit two names for the same file, normally Emacs makes two
  960. different buffers, but it warns you about the situation.
  961.  
  962.    If you wish to avoid visiting the same file in two buffers under
  963. different names, set the variable `find-file-existing-other-name' to a
  964. non-`nil' value.  Then `find-file' uses the existing buffer visiting
  965. the file, no matter which of the file's names you specify.
  966.  
  967.    If the variable `find-file-visit-truename' is non-`nil', then the
  968. file name recorded for a buffer is the file's "truename" (made by
  969. replacing all symbolic links with their target names), rather than the
  970. name you specify.  Setting `find-file-visit-truename' also implies the
  971. effect of `find-file-existing-other-name'.
  972.  
  973. 
  974. File: emacs,  Node: Version Control,  Next: ListDir,  Prev: File Aliases,  Up: Files
  975.  
  976. Version Control
  977. ===============
  978.  
  979.    "Version control systems" are packages that can record multiple
  980. versions of a source file, usually storing the unchanged parts of the
  981. file just once.  Version control systems also record history information
  982. such as the creation time of each version, who created it, and a
  983. description of what was changed in that version.
  984.  
  985.    The GNU project recommends the version control system known as RCS,
  986. which is free software and available from the Free Software Foundation.
  987. Emacs supports use of either RCS or SCCS (a proprietary, but widely
  988. used, version control system that is not quite as powerful as RCS)
  989. through a facility called VC.  The same Emacs commands work with either
  990. RCS or SCCS, so you hardly have to know which one of them you are using.
  991.  
  992. * Menu:
  993.  
  994. * Concepts of VC::              Basic version control information;
  995.                                   checking files in and out.
  996. * Editing with VC::             Commands for editing a file maintained
  997.                                   with version control.
  998. * Variables for Check-in/out::  Variables that affect the commands used
  999.                                   to check files in or out.
  1000. * Log Entries::                 Logging your changes.
  1001. * Change Logs and VC::          Generating a change log file from log
  1002.                                   entries.
  1003. * Old Versions::                Examining and comparing old versions.
  1004. * VC Status::                   Commands to view the VC status of files and
  1005.                                   look at log entries.
  1006. * Renaming and VC::             A command to rename both the source and
  1007.                                   master file correctly.
  1008. * Snapshots::                   How to make and use snapshots, a set of
  1009.                                   file versions that can be treated as a unit.
  1010. * Version Headers::             Inserting version control headers into
  1011.                                   working files.
  1012.  
  1013. 
  1014. File: emacs,  Node: Concepts of VC,  Next: Editing with VC,  Up: Version Control
  1015.  
  1016. Concepts of Version Control
  1017. ---------------------------
  1018.  
  1019.    When a file is under version control, we also say that it is
  1020. "registered" in the version control system.  Each registered file has a
  1021. corresponding "master file" which represents the file's present state
  1022. plus its change history, so that you can reconstruct from it either the
  1023. current version or any specified earlier version.  Usually the master
  1024. file also records a "log entry" for each version describing what was
  1025. changed in that version.
  1026.  
  1027.    The file that is maintained under version control is sometimes called
  1028. the "work file" corresponding to its master file.
  1029.  
  1030.    To examine a file, you "check it out".  This extracts a version of
  1031. the source file (typically, the most recent) from the master file.  If
  1032. you want to edit the file, you must check it out "locked".  Only one
  1033. user can do this at a time for any given source file.  (This kind of
  1034. locking is completely unrelated to the locking that Emacs uses to
  1035. detect simultaneous editing of a file.)
  1036.  
  1037.    When you are done with your editing, you must "check in" the new
  1038. version.  This records the new version in the master file, and unlocks
  1039. the source file so that other people can lock it and thus modify it.
  1040.  
  1041.    Checkin and checkout are the basic operations of version control.
  1042. You can do both of them with a single Emacs command: `C-x C-q'
  1043. (`vc-toggle-read-only').
  1044.  
  1045.